﻿<%@ page language="java"  pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body class="no-skin">
<div class="main-content1">
	<div class="breadcrumbs" id="breadcrumbs">
    	<script type="text/javascript">
    		try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
    	</script>
    	<ul class="breadcrumb"  style="margin-top:10px">
    		<li>
    			<i class="ace-icon fa fa-home home-icon"></i>
    			<a href="#">后台管理</a>						</li>
    		<li class="active">任务管理</li>
    	</ul><!-- 路径结束 -->
	</div>

<!-- /section:basics/content.breadcrumbs -->
<div class="page-content">
<div class="row">
<div class="tab-content no-border padding-0">
	<div class="col-xs-12" >
		<!-- PAGE CONTENT BEGINS -->
		<div class="widget-box transparent">
			<div class="widget-header widget-header-small">
				<h4 class="widget-title blue smaller">
					<i class="ace-icon glyphicon glyphicon-file orange"></i>
						任务新增
				</h4>
			</div>
			<div class="widget-body">
				<div class="widget-main padding-8">
						<!-- #section:pages/profile.feed -->
						<div id="profile-feed-1" class="profile-feed">
							<form id="tiggerForm" class="form-horizontal" role="form">
								<div class="space-1">
								</div>
                                	<div class="form-group">
                                    	<label class="col-sm-3 control-label no-padding-right" for="form-field-1">应用名称</label>
                                    	<div class="col-sm-9">
											<select id="clientCode" name="clientCode" class="col-xs-6">
												<option value="">--请选择--</option>
												<c:forEach items="${appList}" var="app">
													<option value="${app.dictName}">${app.dictName}</option>
												</c:forEach>
											</select>

										</div>
                                  	</div>
								<div class="space-1">
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right" for="form-field-1">任务名称</label>
									<div class="col-sm-9">
										<select id="jobId" name="jobId" class="col-xs-6">
											<option value="">--请选择--</option>
										</select>
									</div>
								</div>
								<div class="space-1">
								</div>
                                	<div class="form-group">
                                    	<label class="col-sm-3 control-label no-padding-right" for="form-field-1">时间间隔</label>
                                    	<div class="col-sm-9">
                                    		<input name="cronExpression" type="text" id="cronExpression" maxlength="100" class="col-xs-6" />

										</div>
                                  	</div>
								<div class="space-1">
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right" for="form-field-1">邮件通知</label>
									<div class="col-sm-9">
										<input name="mailTo" type="text" id="mailTo" maxlength="100" class="col-xs-6" />
										多人以半角;分隔
									</div>
								</div>

							</form>
						</div>
				</div>
			</div>
		</div>
	</div>
	<div id="d_param">
		<form id="param_form">
		<table id="t_param" class="table table-striped table-bordered table-hover"
			   style="margin:0; ">
			<thead>
			<tr>
				<th align="center" nowrap="nowrap" class="center">参数名称</th>
				<th nowrap="nowrap"><strong>参数设置</strong></th>
				<th nowrap="nowrap">备注</th>
			</tr>
			</thead>
			<tbody id="tb_param">

			</tbody>
		</table>
		</form>
	</div>


	<div class="col-xs-12" style="text-align:center"><!-- 按钮行-->
		<div class="clearfix form-actions" style="">
			<button class="btn btn-info" type="button"  onclick="to_submit();">
				<i class="ace-icon fa fa-save bigger-110"></i>
					保 存	
			</button>
			<button class="btn" type="button"  onclick="toBack();">
				<i class="ace-icon fa fa-undo bigger-110"></i>
					返 回	
			</button>
		</div>
	</div>


</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.page-content -->
</div><!-- /.main-content -->
	<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
		<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>			
	</a>		
</div><!-- /.main-container -->

	
	<script src="${resRoot}/plugin/ace-v1.3/assets/js/jquery.validate.min.js"></script>
	<script src="${resRoot}/plugin/jquery-validation/localization/messages_zh.js"></script>
	<script type="text/javascript">
	
	$(function(){
		$("#clientCode").on("change",function(){
			getJobDefines();
		});
		$("#jobId").on("change",function(){
			getJobParamDefines();
		});
		validateForm();
	});
	
	function to_submit(){
		$("#tiggerForm").submit();
	}

	function getJobDefines(){
		$.ajax({
			url : contextPath + "/quartz/getJobList.json",
			type : "post",
			data : "clientCode="+$("#clientCode").val(),
			async : false,
			success : function(data){
				if(null != data){
					$("#jobId").empty();
					$("#jobId").append("<option value=\"\">--请选择--</option>");
					$.each(data,function(i,item){
						$("#jobId").append("<option value=\""+item.jobId+"\">"+item.jobName+"</option>");
					});

				}
			},
			error : function(){
				//$.Alert("服务异常，请稍后尝试！");
			}
		});
	}

	function getJobParamDefines(){
		$.ajax({
			url : contextPath + "/quartz/getPramsByJob.json",
			type : "post",
			data : "jobId="+$("#jobId").val(),
			async : false,
			success : function(data){
				if(null != data){
					$("#tb_param").empty();
					$.each(data,function(i,item){
						var maxstr="";
						var checkEvt="";
						var startStr="";
						if(item.paramType=="string"){
							maxstr="maxlength=\""+item.paramLength+"\"";
							checkEvt = " onblur=\"\"";
						}else if(item.paramType=="number"){
							maxstr="maxlength=\"11\"";
							checkEvt=" onblur=\"checkNumber(this);\"";
						}
						if(item.isRequired=='1'){
							startStr="<span class=\"text-left red\" style='float:left'>*</span>";
						}
						var str="<tr><td align=\"center\">"+item.paramValue+"</td><td align=\"center\"><input name=\"p_"+item.id+"\" class=\"col-xs-6\" "+maxstr+checkEvt+">"+startStr+"</td><td align=\"center\" class=\"red\">"+item.remark+"</td></tr>";
						$("#tb_param").append(str);
					});

				}
			},
			error : function(){
				//$.Alert("服务异常，请稍后尝试！");
			}
		});
	}
		//返回
		function toBack(){
		    window.location.href=contextPath+"/quartz/toJobList.htm";
		}
		
		     
		     //提交表单函数
		     function submitTiggerForm(){

		         $.ajax({
		           url : contextPath + "/quartz/addJob.json",
		           type : "post",
		           data : $("#tiggerForm").serialize()+"&"+$("#param_form").serialize(),
		           async : false,
		           success : function(data){
		           	var msg = eval("("+data+")");
			           if(1==msg.code){
			             $.Alert(msg.message,'',tojobList);
			           }else{
			             $.Alert(msg.message);
			           }
		           },
		           error : function(){
		               //$.Alert("服务异常，请稍后尝试！");
		           }
		         });
		     }
		     
		 function tojobList(){
			location.href = contextPath+"/quartz/toJobList.htm";
		}
		     
		     
		     //表单验证函数
		     function validateForm(){
		       return $("#tiggerForm").validate({
		         errorElement : 'span',
				 errorClass : 'help-block',
				 focusInvalid : false,
				 rules : {
					   "cronExpression" : {
							required : true
						},
						 "mailTo" : {
							 required : true
						 }
				 },
				 
				 highlight: function (e) {
						$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
					},
			
					success: function (e) {
						$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
						$(e).remove();
					},
				 
				 
				 errorPlacement: function (error, element) {
						if(element.is(':checkbox') || element.is(':radio')) {
							var controls = element.closest('div[class*="col-"]');
							if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
							else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
						}
						else if(element.is('.select2')) {
							error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
						}
						else if(element.is('.chosen-select')) {
							error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
						}
						else if(element.is('textarea')) {
							error.appendTo(element.parent());
						}
						else if(element.is('input[type=text]')) {
							error.appendTo(element.parent());
						}
						else error.insertAfter(element.parent());
					},
					submitHandler: function (form) {
						submitTiggerForm();
					},
					invalidHandler: function (form) {
					}
		       });
		     }

		     function checkNumber(obj){
				 if(isNaN(obj.value)){
					 alert('必须输入数字');
					 obj.value='';
				 }
			 }
		</script>
	</body>
</html>
